import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'myblacktag.dart';
import 'myredtag.dart';

class ScenicCard extends StatelessWidget {
  final String price;

  // final List<Widget> tags;
  final String title;
  final List<String> imageUrls;
  final String score;
  final String address;
  final List<String> tag;

  final VoidCallback onPress;

  ScenicCard(this.price, this.title, this.imageUrls, this.score, this.address,
      this.tag, this.onPress);

  @override
  Widget build(BuildContext context) {
    final imageWidth = (MediaQuery.of(context).size.width - 70) / 3;
    final imageHeight = imageWidth - 20;
    return Card(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.all(Radius.circular(15)),
      ),
      color: Colors.white,
      margin: EdgeInsets.only(left: 10, right: 10, top: 10),
      elevation: 0.0,
      child: Padding(
        padding: EdgeInsets.all(10),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Row(
              //关键是这一句  设置横向沾满父控件
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                //标题
                Text(
                  title,
                  style: TextStyle(
                      fontSize: 15,
                      color: Colors.black,
                      fontWeight: FontWeight.bold),
                ),
                //右侧删除图标
                Container(
                  width: 30,
                  height: 30,
                  child: IconButton(
                    padding: EdgeInsets.zero,
                    icon: Icon(
                      Icons.highlight_off,
                      size: 20,
                    ),
                    onPressed: onPress,
                  ),
                ),
              ],
            ),
            //评分
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text(
                  '$score分',
                  style: TextStyle(fontSize: 11, color: Color(0xFFF3A714)),
                ),
                Text(
                  ' | $address',
                  style: TextStyle(fontSize: 11, color: Colors.black),
                ),
              ],
            ),
            SizedBox(
              height: 5,
            ),
            //价格、mark
            Row(
              //设置内容靠下展示
              crossAxisAlignment: CrossAxisAlignment.end,
              children: <Widget>[
                Row(
                  children: _priceBody(price),
                ),
                Row(
                  children: _tagBody(tag),
                ),
              ],
            ),
            SizedBox(
              height: 5,
            ),
            //图片
            Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                _buildImage(imageWidth, imageHeight, imageUrls[1]),
                _buildImage(imageWidth, imageHeight, imageUrls[1]),
                _buildImage(imageWidth, imageHeight, imageUrls[2]),
              ],
            ),
          ],
        ),
      ),
    );
  }

  List<Widget> _tagBody(List<String> tag) {
    List<Widget> titleTag = <Widget>[];
    for (int i = 0; i < tag.length; i++) {
      titleTag.add(MyBlackTag(tag[i], 3));
      titleTag.add(SizedBox(
        width: 5,
      ));
    }
    return titleTag;
  }

  List<Widget> _priceBody(String price) {
    List<Widget> titleTag = <Widget>[];
    if (price != '免费') {
      titleTag.add(Text(
        '¥',
        style: TextStyle(fontSize: 10, color: Color(0xFFE54E45)),
      ));
      titleTag.add(Text(
        '$price',
        style: TextStyle(
            fontSize: 13,
            color: Color(0xFFE54E45),
            fontWeight: FontWeight.bold),
      ));
      titleTag.add(Text(
        '起',
        style: TextStyle(fontSize: 10, color: Color(0xFF1D1D1D)),
      ));
    } else {
      titleTag.add(Text(
        '$price',
        style: TextStyle(
            fontSize: 11,
            color: Color(0xFFE54E45),
            fontWeight: FontWeight.bold),
      ));
      titleTag.add(SizedBox(
        width: 5,
      ));
    }
    return titleTag;
  }

  Widget _buildImage(double width, double height, String imageUrl) {
    return Card(
      color: Colors.transparent,
      elevation: 0.0,
      child: ClipRRect(
        borderRadius: BorderRadius.circular(10.0),
        child: Image.network(
          imageUrl,
          fit: BoxFit.fitWidth,
          width: width,
          height: height,
        ),
      ),
    );
  }
}
